package livesun.justiceeternal.db.love;

import org.greenrobot.greendao.AbstractDao;

import livesun.justiceeternal.db.task.AbsTemplateDbTask;
import livesun.justiceeternal.utils.HandlerFactory;

public class LoveDeleteTask<T> extends AbsTemplateDbTask<T> {
    private final T bean;

    public LoveDeleteTask(Class<? extends T> t, T bean) {
        super(t);
        this.bean = bean;
    }

    @Override
    public void onTaskExecute(AbstractDao<T, ?> dao) {
        if (dao != null) {
            try {
                dao.delete(bean);
                onFinished(bean);
            } catch (Throwable e) {
                e.printStackTrace();
                onFail(e.getMessage());
            }
        }
        return;
    }

    private void onFinished(final T t) {
        HandlerFactory.main().post(new Runnable() {
            @Override
            public void run() {
                deleteSuccess(t);
            }
        });
    }

    private void onFail(final String error) {
        HandlerFactory.main().post(new Runnable() {
            @Override
            public void run() {
                deleteError(error);
            }
        });
    }

    public void deleteSuccess(T t){

    }

    public void deleteError(String error){

    }
}
